// pages/template/dialphone.js
import Router from '../../../utils/router.js';
import Record_server from '../../../utils/page-record.js';
import Record from '../../../utils/page-record.js';
import base from '../../../config/base.js';
import util from '../../../utils/util.js';
import authorize from '../../../utils/authorize';
import goods from '../../../services/goods.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    paymask: {
      type: Object,
      value: ''
    },
    list: String,
    quane: String, //全额购买
    special: String, //特价
    conch: String, //贝壳数量
    isconch: String, //是否是贝壳商品
    phone: String,
    bslnid: String, //店铺id
    segsid: String
  },
  /**
   * 组件的初始数据
   */
  data: {
    goods_id: '', //商品id
    store_id: '', //店铺id
    cnames: '', //商品名称
    imagePath: '', //canvas 路径
    store_recommend: '', //推荐的话语
    shareanimate: '', //分享的动画
    showshare: false, //是否执行动画
    showcard: false, //分享的卡片
    frendanimate: '', //卡片的动画
    locals: 1, //判断是否为已经用canvas画过这张商品图
    goodpath: '', //分享图片的路径
    skutitle: [], //单sku还是双sku
    mixsku: { //选中的两个sku
      one: '',
      two: '',
    },
    arrid: '', //只有一种sku的情况下
    goodsnum: '', //库存量
    sale_price: '', //售价
    please: '请选择品类', //
    goods_num: 1, //购买的数量
    showmsg: 1, //数量超出的提示是否显示
    attr_id: [], //对比出的数组id 传给订单
    onely: false, //只有一行sku并且sku只有一个的时候
    fshow: null,
    transmit: {
      style: 'position:absolute;width:100%;height:100%;background:red;opacity:0;',
      value: ''
    },
    picture: '', //sku默认显示的商品图片
    isconchs: '', //1全额购买 2贝壳购买
    conchsnum: '', //贝壳可抵
    special_price: '', //优惠价（贝壳）

  },
  ready() {
    var _this = this;
    var list = wx.getStorageSync('activity').share_activity;
    if (list == 1) {
      _this.setData({
        fshow: 1
      })
    } else {
      _this.setData({
        fshow: 0
      })
    }
    _this.shareAdd()
    setTimeout(function() {
      _this.shareAdd()
    }, 1000)

  },
  /**
   * 组件的方法列表
   */
  methods: {
    //初始化商品参数
    rest() {
      this.setData({
        goods_id: '', //商品id
        store_id: '', //店铺id
        cnames: '', //商品名称
        imagePath: '', //canvas 路径
        store_recommend: '', //推荐的话语
        shareanimate: '', //分享的动画
        showshare: false, //是否执行动画
        showcard: false, //分享的卡片
        frendanimate: '', //卡片的动画
        locals: 1, //判断是否为已经用canvas画过这张商品图
        goodpath: '', //分享图片的路径
        skutitle: [], //单sku还是双sku
        mixsku: { //选中的两个sku
          one: '',
          two: '',
        },
        arrid: '', //只有一种sku的情况下
        goodsnum: '', //库存量
        sale_price: '', //售价
        please: '请选择品类', //
        goods_num: 1, //购买的数量
        showmsg: 1, //数量超出的提示是否显示
        attr_id: [], //对比出的数组id 传给订单
        getlence: 0, //canvas截取的第一段文字的长度
        onely: false, //只有一行sku并且sku只有一个的时候
        fshow: null,
        authshow: false, //授权保存到相册
        picture: '', //sku默认显示的商品图片
        downbtn: false, //下载图片时是否显示复制保存按钮
        will: false, //保存成功的tip提示
        isconchs: '', //1全额购买 2贝壳购买
        conchsnum: '', //贝壳可抵
        special_price: '', //优惠价（贝壳）
      })
    },
    //去掉选中状态
    restlist() {
      var shop = this.data.shop;
      if (shop.length == 2) {
        var first = shop[0].options;
        var secend = shop[1].options;
        for (var i = 0; i < first.length; i++) {
          first[i].select_active = 1
        }
        for (var i = 0; i < secend.length; i++) {
          secend[i].select_active = 1
        }
        this.setData({
          shop: shop
        })
      } else if (shop.length == 1) {
        var first = shop[0].options;
        // var secend = shop[1].options;
        for (var i = 0; i < first.length; i++) {
          first[i].select_active = 1
        }
        // for (var i = 0; i < secend.length; i++) {
        //   secend[i].select_active = 1
        // }
        this.setData({
          shop: shop
        })
      }
    },
    // 记录分享按钮
    btnClick: function (e) {
      var myEventDetail = {
        share:true
      } // detail对象，提供给事件监听函数
      var myEventOption = {
      } // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
      let p = getCurrentPages().pop();
      Record.clickButton(p, 'Invitation_groupDragon')
    },
    shareAdd() { //卖家分享进买家之后默认显示分享朋友圈
      var _this = this;
      if (this.properties.list == 1) {
        this.setData({
          showshare: true
        })
      }
    },
    createSkus() {
      var _this = this;
      var goodsParam = this.properties.paymask.goodsParam; //goodsParam
      var goodsSku = this.properties.paymask.goodsSku; //goodsSku
      // console.log(goodsParam)
      this.setData({
        param: goodsParam,
        goodssku: goodsSku,
        picture: _this.data.picture == '' ? _this.properties.paymask.goodsPic[0].url : _this.data.picture,
        sale_price: _this.properties.paymask.grad_current_price
      })
      console.log(_this.properties.paymask.goodsPic[0].url)
      console.log(_this.data.picture)
  
      // console.log(goodsParam)
      var newgoodsParam = []; //存放处理好的goodsParam数组
      for (var key in goodsParam) {
        var j = {};
        j.type = key,
          j.options = goodsParam[key];
        newgoodsParam.push(j)
      }
      _this.setData({
        shop: newgoodsParam
      })
      // 第二部处理新数组newgoodsParam中的select_active 为3 则显示无货状态置灰
      //先进行双sku的处理
      if (newgoodsParam.length == 2) {
        var onesku = newgoodsParam[0]; //型号
        var twosku = newgoodsParam[1]; //颜色
        _this.disshop(onesku, 0);
        _this.disshop(twosku, 1);
        if (onesku.options.length == 1 && twosku.options.length == 1 && onesku.options[0].num != 0) { //如果两种规格的sku 并且参数只有一个并且数量不为0的情况上默认选中
          // console.log(onesku)
          // console.log(twosku)
          var oneactive = 'shop[0].options[0].select_active'; //添加默认选中的状态
          var twoactive = 'shop[1].options[0].select_active'; //添加默认选中的状态


          var arrs = []; //传给订单的数组id
          arrs[0] = onesku.options[0].attr_value_id;
          arrs[1] = twosku.options[0].attr_value_id;
          arrs = _this.systemSort(arrs); //进行排
          var newmix = { //不能为空 否则不能提交
            one: arrs[0],
            two: arrs[1]
          }
          _this.setData({
            [oneactive]: 2,
            [twoactive]: 2,
            attr_id: arrs,
            please: '',
            goodsnum: onesku.options[0].num,
            mixsku: newmix,
            special_price: _this.data.goodssku[0].special_price ? _this.data.goodssku[0].special_price : '',
            conchsnum: _this.data.goodssku[0].conch_num ? _this.data.goodssku[0].conch_num : ''
          })
          if (onesku.type == '颜色') { //如果点击的是颜色
            this.setData({
              picture: onesku.options[0].img
            })
          } else if (twosku.type = '颜色') {
            this.setData({
              picture: twosku.options[0].img
            })
          }
        }

      } else if (newgoodsParam.length == 1) {
        var onesku = newgoodsParam[0]; //型号
        _this.disshop(onesku, 0);
        if (onesku.options.length == 1 && onesku.options[0].num != 0) { //只有一种sku并且参数并且总数不为0只有一个默认选中

          var shop = 'shop[0].options[0].select_active';
          var arrs = [];
          arrs.push(onesku.options[0].attr_value_id);
          _this.setData({
            [shop]: 2,
            attr_id: arrs,
            arrid: onesku.options[0].attr_value_id,
            please: '',
            goodsnum: onesku.options[0].num,
            onely: true,
            special_price: _this.data.goodssku[0].special_price ? _this.data.goodssku[0].special_price : '',
            conchsnum: _this.data.goodssku[0].conch_num ? _this.data.goodssku[0].conch_num : ''
          })
          if (onesku.type == '颜色') { //如果点击的是颜色
            this.setData({
              picture: onesku.options[0].img ? onesku.options[0].img : _this.properties.paymask.goodsPic[0].url
            })
          }
          // console.log(onesku)
        }
      } else if (newgoodsParam.length == 0) {
        _this.setData({
          goodsnum: goodsSku[0].num,
        })
      }

      // //价格的处理
      // _this.creatPrice();
    },
    disshop(disku, disnum) { //添加num 判断总数
      // console.log(disku, disnum)
      var goodsSku = this.properties.paymask.goodsSku; //goodsSku
      // console.log(goodsSku)
      var _this = this;
      for (var j = 0; j < disku.options.length; j++) {
        // console.log(j)
        var ids = disku.options[j].attr_value_id;
        var sOff = 0;
        for (var i = 0; i < goodsSku.length; i++) {
          if (goodsSku[i].str_attr_val_id.indexOf(ids) > -1) {
            sOff += Number(goodsSku[i].num);
            if (disku.options[j].attr_name == '颜色' || disku.options[j].attr_id == '颜色') { //在颜色所属下面添加图片
              var img = 'shop[' + disnum + '].options[' + j + '].img'
              _this.setData({
                [img]: goodsSku[i].img
              })
            }
          }
          if (i == goodsSku.length - 1) { //计算添加商品总数
            var itm = 'shop[' + disnum + '].options[' + j + '].num';
            _this.setData({
              [itm]: sOff
            })
          }

        }
      }
    },
    disshops(disku, disnum, id) { //点击的时候比对是否有库存
      var goodsSku = this.properties.paymask.goodsSku; //goodsSku
      var _this = this;
      for (var j = 0; j < disku.options.length; j++) {
        var ids = id;
        var sOff = 0;
        var s = disku.options[j].attr_value_id;
        for (var i = 0; i < goodsSku.length; i++) {
          if (goodsSku[i].arr_attr_val_id.indexOf(ids) > -1 && goodsSku[i].arr_attr_val_id.indexOf(s) > -1) {
            sOff += Number(goodsSku[i].num);
            // console.log('add' + sOff, Number(goodsSku[i].num),ids)
          }
          if (i == goodsSku.length - 1) {
            var itm = 'shop[' + disnum + '].options[' + j + '].num'
            _this.setData({
              [itm]: sOff
            })
          }
        }
      }
    },
    skuOne(e) { //点击第一个sku的时候
      // console.log(e)
      var active = e.target.dataset.active;
      var index = e.target.dataset.index;
      var id = e.target.dataset.name;
      var num = e.target.dataset.num;
      var img = e.target.dataset.img;
      var types = e.target.dataset.types;
      var _this = this;
      if (num == 0) { //库存为0则不进行操作
        return false;
      }
      var one = 'mixsku.one';
      var firstsku = this.data.shop;
      var twosku = firstsku[1];
      this.disshops(twosku, 1, id) //比对是否有库存
      if (firstsku[0].options[index].select_active == 1) { //去除状态
        for (var i = 0; i < firstsku[0].options.length; i++) {
          firstsku[0].options[i].select_active = 1
        }
        firstsku[0].options[index].select_active = 2; //点击选中的时候进行比对
        this.setData({
          [one]: id
        })
        if (types == '颜色') { //如果点击的是颜色
          this.setData({
            picture: img ? img : this.properties.paymask.goodsPic[0].url //有图片显示图片没有图片显示默认
          })
        }
        var newmix = _this.data.mixsku;
        _this.lastCheck(newmix, 2)
      } else {
        for (var i = 0; i < firstsku[0].options.length; i++) {
          firstsku[0].options[i].select_active = 1
        }
        firstsku[0].options[index].select_active = 1; //取消选中的时候
        this.setData({
          [one]: '',
          goodsnum: '',
          please: '请选择' + firstsku[0].type,
          picture: this.properties.paymask.goodsPic[0].url
        })
        if (types == '颜色') { //如果点击的是颜色
          this.setData({
            picture: this.properties.paymask.goodsPic[0].url
          })
        }
        // _this.creatPrice();
        // if(this.data.mixsku.two!==''){//取消选中的时候查看第二个sku是否有选中状态1.如果是选中状态那么获取选中的id 对第一个onesku进行刷新判断是否有库存
        var onesku = _this.data.shop[0];
        var twosku = _this.data.shop[1]
        _this.disshop(twosku, 1); //待验证
        // _this.disshops(onesku, 0, this.data.mixsku.two)
        // }

      }
      this.setData({
        shop: firstsku
      })
    },
    skuTwo(e) { //点击第二个sku的时候
      // console.log(e)
      var _this = this;
      var active = e.target.dataset.active;
      var index = e.target.dataset.index;
      var id = e.target.dataset.name;
      var num = e.target.dataset.num;
      var img = e.target.dataset.img;
      var types = e.target.dataset.types;
      // console.log(img)
      if (num == 0) { //库存为0则不进行操作
        return false;
      }
      var two = 'mixsku.two';
      var firstsku = this.data.shop;
      var onesku = firstsku[0];
      this.disshops(onesku, 0, id) //比对是否有库存
      if (firstsku[1].options[index].select_active == 1) { //去除状态
        for (var i = 0; i < firstsku[1].options.length; i++) {
          firstsku[1].options[i].select_active = 1
        }
        firstsku[1].options[index].select_active = 2; //选中的添加状态
        this.setData({
          [two]: id
        })
        if (types == '颜色') {
          this.setData({
            picture: img ? img : this.properties.paymask.goodsPic[0].url //有图片显示图片没有图片显示默认
          })
        }
        var newmix = _this.data.mixsku;
        _this.lastCheck(newmix, 2) //验证数量
      } else {
        for (var i = 0; i < firstsku[1].options.length; i++) {
          firstsku[1].options[i].select_active = 1
        }
        firstsku[1].options[index].select_active = 1;
        if (types == '颜色') { //如果点击的是颜色
          this.setData({
            picture: this.properties.paymask.goodsPic[0].url
          })
        }
        // debugger
        this.setData({
          [two]: '',
          goodsnum: '',
          please: '请选择' + firstsku[1].type
        })
        // _this.creatPrice()
        var onesku = _this.data.shop[0];
        var twosku = _this.data.shop[1]
        _this.disshop(onesku, 0); //待验证

      }

      this.setData({
        shop: firstsku
      })

    },
    lastCheck(mix, index) { //获取具体数量
      var _this = this;
      var goodsSku = this.properties.paymask.goodsSku; //goodsSku
      if (index == 2) {
        // console.log(mix)
        if (mix.one !== '' && mix.two !== '') {
          for (var i = 0; i < goodsSku.length; i++) {
            if (goodsSku[i].arr_attr_val_id.indexOf(mix.one) > -1 && goodsSku[i].arr_attr_val_id.indexOf(mix.two) > -1) {
              // console.log(goodsSku[i])
              //两种规格全部选中的时候对比出售价 如果是贝壳商品 赋值special_price
              _this.setData({
                attr_id: goodsSku[i].arr_attr_val_id,
                goodsnum: goodsSku[i].num,
                special_price: goodsSku[i].special_price ? goodsSku[i].special_price : '',
                conchsnum: goodsSku[i].conch_num ? goodsSku[i].conch_num : ''
              })
              // console.log(this.data.aa)
              var num = this.data.goods_num;
              if (goodsSku[i].num < num) { //数量超出 提醒
                _this.setData({
                  showmsg: 2,
                  errtip: '对不起，您输入的数量超过了可购买的数量～'
                })
                setTimeout(function() {
                  _this.setData({
                    showmsg: 1,
                    errtip: ''
                  })
                }, 1500)
              }
            }
          }
        }
      } else if (index == 1) {
        for (var i = 0; i < goodsSku.length; i++) {
          if (mix == goodsSku[i].str_attr_val_id) {
            _this.setData({
              attr_id: goodsSku[i].arr_attr_val_id,
              goodsnum: goodsSku[i].num,
              special_price: goodsSku[i].special_price ? goodsSku[i].special_price : '',
              conchsnum: goodsSku[i].conch_num ? goodsSku[i].conch_num : ''
            })
            var num = this.data.goods_num;
            if (goodsSku[i].num < num) { //数量超出 提醒
              _this.setData({
                showmsg: 2,
                errtip: '对不起，您输入的数量超过了可购买的数量～'
              })
              setTimeout(function() {
                _this.setData({
                  showmsg: 1,
                  errtip: ''
                })
              }, 1500)
            }
          }
        }
      }
    },
    skuoneyOne(e) { //只有一行sku的时候点击
      console.log(e)
      console.log(this.data.shop[0])
      console.log(this.data.shop[0].options)
      console.log(this.data.goodssku)
      var _this = this;
      var active = e.target.dataset.active;
      var index = e.target.dataset.index;
      var id = e.target.dataset.name;
      var num = e.target.dataset.num;
      var types = e.target.dataset.types;
      var img = e.target.dataset.img;
      if (num == 0) {
        return false;
      }
      var firstsku = this.data.shop;
      var onesku = firstsku[0];
      console.log(this.data.shop)
      if (firstsku[0].options[index].select_active == 1) { //如果没有选中 那么添加状态选中
        for (var i = 0; i < firstsku[0].options.length; i++) {
          firstsku[0].options[i].select_active = 1
        }
        firstsku[0].options[index].select_active = 2; //选中的添加状态
        _this.setData({
          arrid: id
        })
        if (types == '颜色') {
          this.setData({
            picture: img ? img : this.properties.paymask.goodsPic[0].url //有图片显示图片没有图片显示默认
          })
        }
        var arrid = _this.data.arrid;
        _this.lastCheck(arrid, 1) //验证数量
      } else if (firstsku[0].options[index].select_active == 2) { //取消选中
        for (var i = 0; i < firstsku[0].options.length; i++) {
          firstsku[0].options[i].select_active = 1
        }
        firstsku[0].options[index].select_active = 1;
        if (types == '颜色') {
          this.setData({
            picture: this.properties.paymask.goodsPic[0].url
          })
        }
        // debugger
        var arrid = _this.data.arrid;
        this.setData({
          arrid: '',
          goodsnum: '',
          please: '请选择' + firstsku[0].type
        })
        // _this.creatPrice(); //重置价格
        _this.disshop(onesku, 0); //待验证
      }
      this.setData({
        shop: firstsku
      })
    },
    creatPrice() { //取最大和最小的价格
      var goodsSku = this.properties.paymask.goodsSku; //goodsSku
      var _this = this;
      var arr = [];
      for (var i = 0; i < goodsSku.length; i++) {
        if (this.data.isconchs == 1) {
          // arr.push(goodsSku[i].sale_price)
        } else if (this.data.isconchs == 2) {
          arr.push(goodsSku[i].special_price)
        }

      }
      // debugger
      console.log(arr)
      var arrs = this.systemSort(arr);
      if (this.data.shop.length == 2) {
        if (this.data.mixsku.one == '' || this.data.mixsku.two == '') {
          var section = '';
          if (Number(arrs[0]) == Number(arrs[arrs.length - 1])) {
            section = arrs[0]
          } else {
            section = arrs[0] + '-' + arrs[arrs.length - 1];
          }
          //赋值售价和特惠价格（特惠价格与贝壳数量需判断前提如果存在）
          this.setData({
            // sale_price: section,
            special_price: section,
            conchsnum: goodsSku[0].conch_num ? goodsSku[0].conch_num : ''
          })
        }
      }
      if (this.data.shop.length == 1) {
        if (this.data.arrid == '') { //没有选中的时候要显示区间价格
          var section = '';
          if (Number(arrs[0]) == Number(arrs[arrs.length - 1])) {
            section = arrs[0]
          } else {
            section = arrs[0] + '-' + arrs[arrs.length - 1];
          }
          this.setData({
            // sale_price: section,
            special_price: section,
            conchsnum: goodsSku[0].conch_num ? goodsSku[0].conch_num : ''
          })
        } else if (this.data.onely) { //当只有一行sku 并且参数块只有一个的时候 默认选中第一个
          var section = '';
          if (Number(arrs[0]) == Number(arrs[arrs.length - 1])) {
            section = arrs[0]
          } else {
            section = arrs[0] + '-' + arrs[arrs.length - 1];
          }
          this.setData({
            // sale_price: section,
            special_price: section,
            conchsnum: goodsSku[0].conch_num ? goodsSku[0].conch_num : ''
          })
        }
      }
      if (this.data.shop.length == 0) {
        // console.log(goodsSku[0].sale_price)
        // console.log(goodsSku[0].special_price)
        // console.log(goodsSku[0].conch_num )
        this.setData({
          // sale_price: goodsSku[0].sale_price,
          special_price: goodsSku[0].special_price ? goodsSku[0].special_price : '',
          conchsnum: goodsSku[0].conch_num ? goodsSku[0].conch_num : ''
        })
      }

    },
    skuAdd() { //点击数量递增
      var _this = this;
      var goodsnum = _this.data.goods_num;
      var num = _this.data.goodsnum;
      goodsnum++
      _this.setData({
        goods_num: goodsnum
      })
      if (this.data.shop.length == 2) {
        if (this.data.mixsku.one !== '' && this.data.mixsku.two !== '') {
          if (goodsnum > num) {
            _this.setData({
              // showtip: 2,
              showmsg: 2,
              errtip: '对不起，您输入的数量超过了可购买的数量～',
              goods_num: num
            })
            setTimeout(function() {
              _this.setData({
                showmsg: 1,
                errtip: ''
              })
            }, 1500)
          }
        }
      } else if (this.data.shop.length == 1) {

        if (this.data.arrid !== '') {
          if (goodsnum > num) {
            _this.setData({
              // showtip: 2,
              showmsg: 2,
              errtip: '对不起，您输入的数量超过了可购买的数量～',
              goods_num: num
            })
            setTimeout(function() {
              _this.setData({
                showmsg: 1,
                errtip: ''
              })
            }, 1500)
          }
        }
      } else if (this.data.shop.length == 0) {
        if (goodsnum > num) {
          _this.setData({
            // showtip: 2,
            showmsg: 2,
            errtip: '对不起，您输入的数量超过了可购买的数量～',
            goods_num: num
          })
          setTimeout(function() {
            _this.setData({
              showmsg: 1,
              errtip: ''
            })
          }, 1500)
        }
      }

    },
    skuDel() { //数量递减
      var _this = this;
      var goodsnum = _this.data.goods_num;
      var num = _this.data.goodsnum;
      goodsnum--;
      if (goodsnum < num) {
        _this.setData({
          showmsg: 1,
          errtip: ''
        })
      }
      if (goodsnum == 0) {
        return false;
      }
      _this.setData({
        goods_num: goodsnum
      })
    },
    payOrder() { //提交订单
      var _this = this;
      console.log(_this.data.goodsnum);
      console.log(_this.data.goods_num)
      if (this.data.shop.length == 2) {
        if (this.data.mixsku.one == '' || this.data.mixsku.two == '') {
          _this.setData({
            // showtip: 2,
            showmsg: 2,
            errtip: '请选择好商品参数'
          })
          setTimeout(function() {
            _this.setData({
              showmsg: 1,
              errtip: ''
            })
          }, 1500)
          return false;
        }
      } else if (this.data.shop.length == 1) {
        if (_this.data.arrid == '') {
          _this.setData({
            // showtip: 2,
            showmsg: 2,
            errtip: '请选择好商品参数'
          })
          setTimeout(function() {
            _this.setData({
              showmsg: 1,
              errtip: ''
            })
          }, 1500)
          return false;
        }
      }
      if (_this.data.goodsnum < _this.data.goods_num) {
        console.log(7777)
        _this.setData({
          // showtip: 2,
          showmsg: 2,
          errtip: '对不起，您输入的数量超过了可购买的数量～'
        })
        setTimeout(function() {
          _this.setData({
            showmsg: 1,
            errtip: ''
          })
        }, 1500)
        return false;
      }
      console.log(this.properties.paymask)
      var goods_id = this.properties.paymask.goods_id;
      var store_id = this.properties.paymask.store_id;
      var num = this.data.goods_num;
      var attr = '';
      if (this.data.attr_id.length == 2) {
        var arrs = [];
        console.log(this.data.attr_id)
        arrs = _this.systemSort(this.data.attr_id); //进行排
        attr = arrs[0] + ',' + arrs[1]
      } else if (this.data.attr_id.length == 1) {
        console.log(this.data.attr_id)
        attr = this.data.attr_id.join('')
      }
      this.setData({
        showmodalstatus: false,
        picture: ''
      })
      console.log(_this.properties.bslnid)
      //验证贝壳是否足够支付订单 需验证已授权的贝壳数量
      // if (this.data.isconchs == 2) { //贝壳购买

      // } else if (this.data.isconchs == 1) { //全额购买
      // var mixsku = {
      //   one: '',
      //   two: ''
      // }
      // _this.setData({
      //   mixsku: mixsku,
      //   arrid: ''
      // })
        Router.go('jielong', `segsid=${_this.properties.segsid}&bslnid=${_this.properties.bslnid}&sku_str=${attr}&goods_num=${num}&sale_price=${_this.properties.paymask.grad_current_price}&types=${1}`)
          this.restlist()
          this.rest();
      // }
    },
    systemSort(array) { //排序函数
      return array.sort(function(a, b) {
        return a - b;
      });
    },
    showmodal: function(e) { //显示商品参数的遮罩
      if (e.currentTarget.dataset.isconchs == 1) {
        this.setData({
          isconchs: 1
        })
      } else if (e.currentTarget.dataset.isconchs == 2) {
        this.setData({
          isconchs: 2
        })
      }
      this.createSkus();
      var animation = wx.createAnimation({
        duration: 500,
        timingFunction: "ease",
        delay: 0
      })
      this.animation = animation
      animation.translateY(500).step()
      this.setData({
        animationData: animation.export(),
        showmodalstatus: true
      })
      setTimeout(function() {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export()
        })
      }.bind(this), 350)
      let p = getCurrentPages().pop();
      Record.clickButton(p, 'begin_groupDragon')
    },
    hidemodal: function() { //商品参数隐藏遮罩层
      this.setData({ //隐藏数量超出的提示框
        showtip: 1,
        showmsg: 1
      })
      var animation = wx.createAnimation({
        duration: 500,
        timingFunction: "ease",
        delay: 0
      })
      this.animation = animation
      animation.translateY(500).step()
      this.setData({
        animationData: animation.export(),
      })
      setTimeout(function() {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export(),
          showmodalstatus: false
        })
      }.bind(this), 350)
    },
    sharaMenu() { //点击分享按钮弹出
      this.closeVedio()
      var animation = wx.createAnimation({
        duration: 500,
        timingFunction: "ease",
        delay: 100
      })
      this.shareanimate = animation
      animation.translateY(200).step()
      this.setData({
        animation: animation.export(),
        showshare: true
      })
      setTimeout(function() {
        animation.translateY(0).step()
        this.setData({
          shareanimate: animation.export()
        })
      }.bind(this), 350)
    },
    hideShare() { //隐藏分享遮罩
      var animation = wx.createAnimation({
        duration: 500,
        timingFunction: "ease",
        delay: 0
      })
      this.shareanimate = animation
      animation.translateY(200).step()
      this.setData({
        animationData: animation.export(),
      })
      setTimeout(function() {
        animation.translateY(0).step()
        this.setData({
          shareanimate: animation.export(),
          showshare: false
        })
      }.bind(this), 350)
    },
    showCards() {
      var _this = this;
      this.setData({
        goods_id: _this.properties.paymask.goods_id,
        store_id: _this.properties.paymask.store_id
      })
    },

    souterStore() { //去到买家店铺
      let _this = this;
      Router.go(`store`)
    },
    getLength(str) {
      if (/[a-z]/i.test(str)) {
        return str.match(/[a-z]/ig).length;
      }
      return 0;
    },
    hideAuth() {
      this.setData({
        authshow: false
      })

    },
    bigPicture(e) { //点击查看sku商品大图
      var src = 'https:' + e.currentTarget.dataset.img;
      wx.previewImage({
        current: src,
        urls: [src]
      })
    },
    closeVedio() { //点击canvas的时候要隐藏视频
      var myEventDetail = {}
      myEventDetail.full = false
      // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
    }
  }
})